import copy
#1给定以下列表, 通过匿名函数和常规函数根据键age来排序
classes = [
    {"name": "abyss", "age": 25, "grade": "A"},
    {"name": "kin", "age": 23, "grade": "B"},
    {"name": "tian", "age": 24, "grade": "B"},
    {"name": "hun", "age": 26, "grade": "A"},
    {"name": "exe", "age": 21, "grade": "A"}
]

def age_(x):
    return x["age"]


#2021年马上就要到来了, 通过map函数将上述同学的age+1
def age_add_1():
    classes1 = copy.deepcopy(classes)
    age_add = map(lambda x: x["age"]+1, classes1)
    list_age = list(age_add)
    for i in range(len(classes1)):
        classes1[i]["age"] = list_age[i]
    print(classes1)

def fil_gradeA():
    fil_grade = filter(lambda x: x["grade"] is "A", classes)
    print(list(fil_grade))

#递归重构Fibonacci函数
#在数学上，斐波纳契数列以如下被以递推的方法定义：F(1)=1，F(2)=1,F(3)=2,F(4)=3.....F(n)=F(n-1)+F(n-2)


def fibo(n):
    n = int(n)
    result = 0
    if n == 1 or n == 2:
        result = 1
    elif n > 3 or n == 3:
        result = fibo(n-1)+ fibo(n-2)
    return result
# n = input("请输入一个整数作为Fibonacci函数的输入：")
# print(fibo(n))
# # print(b)


if __name__ == "__main__":
    print("通过匿名函数排序如下：")
    print(sorted(classes,key = lambda x : x["age"]))
    print("通过常规函数排序如下：")
    print(sorted(classes,key = age_))
    print("age+1后的列表如下：")
    age_add_1()
    print("筛选出的'A'列表如下:")
    fil_gradeA()
    n = input("请输入一个整数作为Fibonacci函数的输入：")
    print(f"fibo{n}的结果是：{fibo(n)}")







